import { View, Image } from "@tarojs/components";
import { AtList, AtListItem } from "taro-ui";
import { useState } from "react";
import { getInspectDataApi } from "../../../utils/api";
import Taro, { useDidShow, useRouter } from "@tarojs/taro";
import { formatTime2 } from "../../../utils/to";
import { baseUrl } from "../../../utils/http";
import "./index.scss";
const detect_result = {
  1: "待完成",
  2: "正常",
  3: "蚁情",
  4: "入侵",
  5: "低电量"
};
const state_list = {
  1: "正常",
  2: "发现蚁情",
  3: "发现蚁情但量不多，需再观察",
  4: "发现蚁情但已撤离，无需灭杀",
  5: "装置异常",
  6: "装置被入侵破坏",
  7: "装置丢失",
  8: "装置被移位",
  9: "其他"
};
const measure_list = {
  1: "无操作",
  2: "简单恢复",
  3: "替换电池",
  4: "替换装置",
  5: "灭蚁",
  6: "推迟灭蚁(再观察)",
  9: "其他"
};
const Index = () => {
  const router = useRouter();

  const [detailInfo, set_detailInfo] = useState({});

  useDidShow(() => {
    getInfo();
  });

  // 获取探测数据
  const getInfo = async () => {
    const res = await getInspectDataApi({
      inspect_id: router.params.id
    });
    if (res.res === 0) {
      set_detailInfo(res.record);
    } else {
      Taro.atMessage({
        message: res.msg,
        type: "warning"
      });
    }
  };

  return (
    <View className="detect-detail">
      {detailInfo.image_path ? (
        <Image
          style="width: 100%;"
          mode="widthFix"
          src={baseUrl + detailInfo.image_path}
        />
      ) : (
        <View className="null">暂无工程图片</View>
      )}
      <AtListItem title="所属工程" extraText={detailInfo.project_name} />
      <AtListItem title="布点名称" extraText={detailInfo.point_name} />
      <AtListItem
        title="探测类型"
        extraText={detect_result[detailInfo.warn_type]}
      />
      <AtListItem title="检查结果" extraText={state_list[detailInfo.state]} />
      <AtListItem
        title="采取措施"
        extraText={measure_list[detailInfo.measure_type]}
      />
      <AtListItem title="分配人员" extraText={detailInfo.user_name} />
      <AtListItem title="备注信息" extraText={detailInfo.comment} />
      <AtListItem
        title="探测创建时间"
        extraText={formatTime2(detailInfo.create_timestamp * 1000)}
      />
      <AtListItem
        title="探测处理时间"
        extraText={
          detailInfo.done_timestamp == 0
            ? "暂无处理"
            : formatTime2(detailInfo.done_timestamp * 1000)
        }
      />
    </View>
  );
};

export default Index;
